<?php

class Mnt_UserController extends Base_Controller_Action
{
    
	public function manageAction()
	{
		$request = $this->getRequest();

		//check order
		$orderBy = $request->getParam('orderby');
		$orderFields = array('uid','role','state','login');
		if (empty($orderBy) || !in_array($orderBy, $orderFields)) {
			$orderBy = 'role';
		}

		$orderWay = $request->getParam('orderway');
		if (empty($orderWay) || !in_array($orderWay, array('ASC','DESC'))) {
			$orderWay = 'ASC';
		}

		//fetch data
		$dbTable = new Table_User();
		Zend_Paginator::setCache(Zend_Registry::get('Zend_Cache'));
		$this->view->paginator = Zend_Paginator::factory(
				$dbTable->select()
					->order($orderBy.' '.$orderWay)
			);

		//check page
		if (is_numeric($request->getParam('page'))) {
			$this->view->paginator->setCurrentPageNumber($request->getParam('page'));
		}
		
		$this->view->request = $request;
	}
	
	public function createAction()
	{
		$this->form = new Form_User_Create();
		$this->create('user');
	}
	
	public function modifyAction()
	{
		$this->form = new Form_User_Modify();
        $this->modify('user');
	}
	
	public function deleteAction()
	{
		$this->form = new Form_User_Delete();
        $this->delete('user');
	}
}